package com.jinbo.footmessage.utils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class ActivitiesHelper {


	private LinkedList<Activity> mActs;
	private static ActivitiesHelper instance = null;

	private ActivitiesHelper() {
		mActs = new LinkedList<Activity>();
	}

	public synchronized static ActivitiesHelper getInstance() {
		if (instance == null) {
			instance = new ActivitiesHelper();
		}
		return instance;
	}

	public void addActivity(Activity act) {
		synchronized (ActivitiesHelper.this) {
			mActs.addFirst(act);
		}
	}

	public void removeActivity(Activity act) {
		synchronized (ActivitiesHelper.this) {
			if (mActs != null && mActs.indexOf(act) >= 0) {
				mActs.remove(act);
			}
		}
	}




    public void closeAll() {
        synchronized (ActivitiesHelper.this) {
            Activity act;
            while (mActs.size() != 0) {
                act = mActs.poll();
                act.finish();
            }
        }
    }

}
